package com.sangmo.fts.api.basic;

import com.sangmo.boot.framework.api.utils.ApiResponse;
import com.sangmo.boot.framework.data.filter.PageResult;
import com.sangmo.boot.framework.plugin.dataview.data.DataViewPageSearch;
import com.sangmo.fts.basic.model.FileUpload;
import com.sangmo.fts.basic.service.FileUploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.HashMap;

@Controller
@RequestMapping(value = "/file/v1")
public class UploadApi {

    @Autowired
    private FileUploadService fileUploadService;

    @PostMapping(value = "/upload/file")
    @ResponseBody
    public ApiResponse uploadFile(@RequestParam("file") MultipartFile file, HttpServletRequest request) throws Exception {
        return ApiResponse.make(fileUploadService.uploadFile(file, request));
    }

//    @PostMapping(value = "/{id}/read")
//    @ResponseBody
//    public ApiResponse<FileUpload> read(@PathVariable("id") Long id) {
//        return ApiResponse.make(fileUploadService.find(id));
//    }
//
//    @PostMapping(value = "/search")
//    @ResponseBody
//    public ApiResponse<PageResult<FileUpload>> search( @RequestBody @Valid DataViewPageSearch<HashMap> ps) {
//        return ApiResponse.make(fileUploadService.search(ps));
//    }

}
